<template>
	<view class="route">
		<view class="cont">
			<view class="imgcont">
				<image class="img" :src="info.images" mode="widthFix"></image>
			</view>
			<!-- <view class="text">
				<view class="name">
					{{info.name}}
				</view>
				<view class="desc">
					{{info.title}}
				</view>

			</view> -->
		</view>
		<view class="footer">
			<view class="btn .def-bgcol rowbox " @click="handleBuy">
				{{info.name}}
			</view>
		</view>
		<u-modal :show="showMa" @confirm="showMa=false">
			<view class="slot-content">
				<view class="imgcont">
					<image :src="ma" mode="widthFix" class="img"></image>
				</view>
				<view class="text">
					如果你想继续使用该平台，请联系客服
				</view>
			</view>
		</u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				showMa: false,
				id: '',
				info: '',
				unionid: '',
				ma: ''
			};
		},
		async onLoad(options) {
			if (options.id) {
				this.id = Number(options.id)
				await this.getUserInfo()
				await this.getInfo()
				this.getma()
			}
		},
		methods: {
			async getUserInfo() {
				await this.$req.post('/shanghu/shanghuuserInfo', {

					uid: uni.getStorageSync('uid')
				}).then((res) => {

					let info = res.data.data

					this.unionid = info.unionid
				})
			},
			getInfo() {

				this.$req.post('/web/vippackageinfo', {
					id: this.id,
					uid: uni.getStorageSync('uid'),
					unionid: this.unionid
				}).then((res) => {
					let info = res.data.data
					this.info = info
				})
			},
			getma() {
				this.$req.post('/shanghu/kefuimage', {}).then((res) => {
					this.ma = res.data.data
				})
			},
			handleBuy() {
				const info = wx.getSystemInfoSync()
				if (info.system.indexOf('Android') > -1) {
					let req = {
						uid: uni.getStorageSync('uid'),
						vippackageid: this.info.id
					}
					uni.showLoading({

					})
					this.$req.post('/shanghu/wechatpay', req).then((res) => {
						uni.hideLoading()
						let data = res.data
						if (data.code === 0) {
							let paydata = data.data
							this.pay(paydata)
						} else {
							wx.showToast({
								mask: true,
								icon: 'none',
								title: data,
								msg
							})
						}
					})
				} else {
					this.showMa = true
				}


			},
			pay(paydata) {
				wx.requestPayment({
					nonceStr: paydata.nonceStr, // 随机字符串
					package: paydata.package, // 固定值
					signType: paydata.signType, // 统一下单订单号 
					timeStamp: paydata.timeStamp, // 时间戳（单位：秒）
					paySign: paydata.sign, // 签名，这里用的 MD5/RSA 签名
					success(res) {

						uni.navigateBack()

					},
					fail(e) {
						wx.showToast({
							mask: true,
							icon: '支付失败',
							title: data,
							msg
						})

						console.log(e, 8888)
					}
				})
			}
		},


	}
</script>

<style lang="scss" scoped>
	.route {
		min-height: 100vh;
		// background-color: #f5f5f5;
		padding-bottom: 150rpx;

		.slot-content {
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;

			.imgcont {

				width: 100%;


				.img {
					display: block;
					width: 100%;
					height: 100%;
				}
			}

			.text {
				margin-top: 20rpx;
				font-size: 26rpx;
			}
		}

		.cont {
			.imgcont {
				width: 100%;


				.img {
					display: block;
					width: 100%;
					height: 100%;
				}
			}

			.text {
				margin-top: 40rpx;
				padding: 0 24rpx;

				color: #333;

				.name {
					font-size: 30rpx;
					font-weight: 500;
				}

				.desc {
					margin-top: 20rpx;
					color: #999;
					font-size: 28rpx;
				}
			}
		}

		.footer {
			position: fixed;
			bottom: 0;
			left: 0;
			z-index: 10;
			width: 100%;
			background: #fff;
			padding: 10rpx 20rpx 0 20rpx;
			height: 120rpx;
			box-shadow: 0 0 4px 2px #eeecef;
			box-sizing: border-box;

			.btn {
				width: 100%;
				font-size: 28rpx;
				height: 90rpx;
				border-radius: 20rpx;
				color: #fff;
			}
		}
	}
</style>